﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using viBook.Models;

namespace viBook.ModelBinders
{
    public class ContentTagsBinders : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var tags = controllerContext.HttpContext.Request["ContentTagName"];
            if (string.IsNullOrEmpty(tags)) return new List<ContentTag>();
            var splittedTags = tags.Split(';');
            return splittedTags.Distinct().Select(t => new ContentTag
            {
                ContentTagName = t.Trim()
            }).ToList();
        }
    }
}